﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Class</title>
<meta name="GENERATOR" content="WinCHM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body><A 
href="http://www.tutorialspoint.com/python/python_classes_objects.htm"><FONT 
face=Courier>http://www.tutorialspoint.com/python/python_classes_objects.htm</FONT></A><BR>
<H2 
style="MARGIN-TOP: 10px; MARGIN-BOTTOM: 10px; WORD-SPACING: 0px; FONT: bold 16px/1.5 Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(255,255,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">Example:</H2>
<P 
style="WORD-SPACING: 0px; FONT: 11px verdana, helvetica, arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(255,255,255); TEXT-ALIGN: justify; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">Following 
is the example of a simple Python class:</P>
<TABLE class=src 
style="BORDER-RIGHT: rgb(170,170,170) 1px solid; BORDER-TOP: rgb(170,170,170) 1px solid; PADDING-LEFT: 5px; WORD-SPACING: 0px; FONT: 11px verdana, helvetica, arial, sans-serif; VERTICAL-ALIGN: top; TEXT-TRANSFORM: none; BORDER-LEFT: rgb(170,170,170) 1px solid; WIDTH: 552px; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; BORDER-BOTTOM: rgb(170,170,170) 1px solid; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: rgb(241,241,241); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px" 
cellPadding=5>
  
  <TR>
    <TD 
    style="BORDER-RIGHT: rgb(170,170,170) 1px solid; BORDER-TOP: rgb(170,170,170) 1px solid; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: top; BORDER-LEFT: rgb(170,170,170) 1px solid; BORDER-BOTTOM: rgb(170,170,170) 1px solid; FONT-FAMILY: verdana, helvetica, arial, sans-serif; BORDER-COLLAPSE: collapse; TEXT-ALIGN: left"><PRE style="MARGIN-TOP: 0px; FONT-SIZE: 12px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 0px; FONT-FAMILY: 'Courier New', monospace">class Employee:
   'Common base class for all employees'
   empCount = 0

   def __init__(self, name, salary):
      self.name = name
      self.salary = salary
      Employee.empCount += 1
   
   def displayCount(self):
     print "Total Employee %d" % Employee.empCount

   def displayEmployee(self):
      print "Name : ", self.name,  ", Salary: ", self.salary
</PRE></TD></TR></TABLE>
<UL 
style="WORD-SPACING: 0px; FONT: 11px verdana, helvetica, arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(255,255,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">
  <LI>
  <P 
  style="FONT-FAMILY: verdana, helvetica, arial, sans-serif; TEXT-ALIGN: justify">The 
  variable<SPAN class=Apple-converted-space>&nbsp;</SPAN><I>empCount</I><SPAN 
  class=Apple-converted-space>&nbsp;</SPAN>is a class variable whose value would 
  be shared among all instances of a this class. This can be accessed as<SPAN 
  class=Apple-converted-space>&nbsp;</SPAN><I>Employee.empCount</I><SPAN 
  class=Apple-converted-space>&nbsp;</SPAN>from inside the class or outside the 
  class.</P>
  <LI>
  <P 
  style="FONT-FAMILY: verdana, helvetica, arial, sans-serif; TEXT-ALIGN: justify">The 
  first method<SPAN 
  class=Apple-converted-space>&nbsp;</SPAN><I>__init__()</I><SPAN 
  class=Apple-converted-space>&nbsp;</SPAN>is a special method which is called 
  class constructor or initialization method that Python calls when you create a 
  new instance of this class.</P>
  <LI>
  <P 
  style="FONT-FAMILY: verdana, helvetica, arial, sans-serif; TEXT-ALIGN: justify">You 
  declare other class methods like normal functions with the exception that the 
  first argument to each method is<SPAN 
  class=Apple-converted-space>&nbsp;</SPAN><I>self</I>. Python adds the<SPAN 
  class=Apple-converted-space>&nbsp;</SPAN><I>self</I><SPAN 
  class=Apple-converted-space>&nbsp;</SPAN>argument to the list for you; you 
  don't need to include it when you call the methods.</P></LI></UL>
<H1 
style="MARGIN-BOTTOM: 0px; WORD-SPACING: 0px; FONT: 18px/1.5 Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(255,255,255); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">Creating 
instance objects:</H1>
<P 
style="WORD-SPACING: 0px; FONT: 11px verdana, helvetica, arial, sans-serif; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BACKGROUND-COLOR: rgb(255,255,255); TEXT-ALIGN: justify; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">To 
create instances of a class, you call the class using class name and pass in 
whatever arguments its<SPAN 
class=Apple-converted-space>&nbsp;</SPAN><I>__init__</I><SPAN 
class=Apple-converted-space>&nbsp;</SPAN>method accepts.</P>
  <P 
  style="FONT-FAMILY: verdana, helvetica, arial, sans-serif; TEXT-ALIGN: justify">
<TABLE class=src 
style="BORDER-RIGHT: rgb(170,170,170) 1px solid; BORDER-TOP: rgb(170,170,170) 1px solid; PADDING-LEFT: 5px; WORD-SPACING: 0px; FONT: 11px verdana, helvetica, arial, sans-serif; VERTICAL-ALIGN: top; TEXT-TRANSFORM: none; BORDER-LEFT: rgb(170,170,170) 1px solid; WIDTH: 552px; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; BORDER-BOTTOM: rgb(170,170,170) 1px solid; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: rgb(241,241,241); TEXT-ALIGN: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px" 
cellPadding=5>
  
  <TR>
    <TD 
    style="BORDER-RIGHT: rgb(170,170,170) 1px solid; BORDER-TOP: rgb(170,170,170) 1px solid; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: top; BORDER-LEFT: rgb(170,170,170) 1px solid; BORDER-BOTTOM: rgb(170,170,170) 1px solid; FONT-FAMILY: verdana, helvetica, arial, sans-serif; BORDER-COLLAPSE: collapse; TEXT-ALIGN: left"><PRE style="MARGIN-TOP: 0px; FONT-SIZE: 12px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 0px; FONT-FAMILY: 'Courier New', monospace">"This would create first object of Employee class"
emp1 = Employee("Zara", 2000)
"This would create second object of Employee class"
emp2 = Employee("Manni", 5000)</PRE></TD></TR></TABLE>       
           </P></body>
</html>
